/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package miage.rest.validation;

/**
 *
 * @author marya
 */
public class LengthValidator extends AbstractValidator{
    private int length;

    public LengthValidator(int length){
        super();
        this.length = length;
    }

    public boolean isValid(String data){
        if(data != null  && data.length() > length){
            addMessage("Exception occured : data '"+data+"' has more length than expected");
            return false;
        }
        return true;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final LengthValidator other = (LengthValidator) obj;
        if (this.length != other.length) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 79 * hash + this.length;
        return hash;
    }



}
